<template>
  <div id="myChart" :style="{height:height,width:width}"></div>
</template>

<script>
export default {
  components:{
    myline
  },
  props: {
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '100%'
    },
    autoResize: {
      type: Boolean,
      default: true
    },
    chartData: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      chart:null
    }
  },
  mounted() {
    this.initChart()
    this.__resizeHandler = debounce(() => {
      if (this.chart) {
        this.chart.resize()
      }
    }, 100)
    window.addEventListener('resize', this.__resizeHandler)
    // this.$nextTick(() => {
    //   this.initChart()
    // })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart(){
        // 基于准备好的dom，初始化echarts实例
        this.chart = this.$echarts.init(document.getElementById('myChart'))
        // 绘制图表
        this.chart.setOption({
          title: { text: '综合分析曲线' },
          tooltip: {},
          grid: {
            left: 10,
            right: 20,
            bottom: 20,
            top: 30,
            containLabel: true
          },
          xAxis: {
              data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
          },
          yAxis: {},
          series: [{
              name: '销量',
              type: 'line',
              data: [5, 20, 36, 10, 10, 20]
          }]
      });
    }
  }
}